import { encode as b64e } from '@/utils/base64'
import { useUserStore } from '@/stores/user'

// 获取当前用户（若未登录则自动登录）
export const getCurrentUser = async () => {
	const store = useUserStore()
	await store.ensureLogin()
	return store.userInfo
}

// 生成自查自纠外链 URL（H5 跳转使用）
export const buildZczjUrl = (userInfo) => {
	if (!userInfo?.omDepts) return ''
	const mobile = b64e(userInfo.phonenumber || '')
	const userName = b64e(userInfo.userName || '')
	const creditCode = b64e(userInfo.omDepts.creditCode || '')
	return `https://szesisc.envchina.com?mobile=${mobile}&userName=${userName}&creditCode=${creditCode}`
}

export default {
	getCurrentUser,
	buildZczjUrl,
}
